package com.nit.mapper;

import com.nit.dto.GoodsDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ShopGoodsMapper {

    @Select("<script> " +
            "SELECT COUNT(*) " +
            "FROM " +
            "tb_goods tg, tb_shop_goods tsg " +
            "WHERE " +
            "tg.is_delete = 0 " +
            "AND tsg.is_delete = 0 " +
            "AND tsg.shop_id = 0 " +
            "AND tg.goods_id = tsg.goods_id " +
            "<if test='goodsName != null'> AND tg.goods_name LIKE CONCAT('%', #{goodsName}, '%') </if>" +
            "<if test='goodsCate != null'> AND tg.goods_cate = #{goodsCate} </if>" +
            "</script> ")
    Long count4Table(@Param("goodsName") Object goodsName,
                     @Param("goodsCate") Object goodsCate);

    @Select("<script> " +
            "SELECT " +
            "tg.goods_id, tg.goods_name, " +
            "tg.goods_cate, tsg.sells_in, " +
            "tsg.sells_out, tsg.gmt_create, " +
            "tsg.sg_count AS 'goods_count' " +
            "FROM " +
            "tb_goods tg, tb_shop_goods tsg " +
            "WHERE " +
            "tg.is_delete = 0 " +
            "AND tsg.is_delete = 0 " +
            "AND tsg.shop_id = 0 " +
            "AND tg.goods_id = tsg.goods_id " +
            "<if test='goodsName != null'> AND tg.goods_name LIKE CONCAT('%', #{goodsName}, '%') </if>" +
            "<if test='goodsCate != null'> AND tg.goods_cate = #{goodsCate} </if>" +
            "ORDER BY goods_id DESC " +
            "LIMIT #{start}, #{length} " +
            "</script> ")
    List<GoodsDTO> list4Table(@Param("start") Integer start,
                              @Param("length") Integer length,
                              @Param("goodsName") Object goodsName,
                              @Param("goodsCate") Object goodsCate);
}
